<?php
/**
 * PublicController.class.php
 * Public控制器
 *
 * @author  王中艺
 * @date    2016-10-25
 */

namespace Home\Controller;
use Think\Controller;

class PublicController extends Controller{

    /**
     * 数据迁移
     * date
     * @return [type] [description]
     */
    function dataMove(){
        exit;
        set_time_limit(0);
        $tableName  = I('get.tb_name');
        echo 'table:'.$tableName.'<br>';
        $Model  = new \Think\Model();
        $Model->db(1, 'mysql://root:root@127.0.0.1:3306/xinletu_v1_pro');
        $Model->db(2, 'mysql://root:root@127.0.0.1:3306/xinletu_new');

        $page   = 1;
        $pageCount  = 100;
        $itemCount  = 0;
        while(true){
            $list   = $Model->db(1)->table($tableName)
                ->page($page, $pageCount)
                ->select();
            if(!$list)  break;
            foreach($list as $val){
                $ret    = $Model->db(2)->table($tableName)->add($val);
            }
            // if($tableName == 't_teacher'){
            //     foreach($list as &$val){
            //         $val['create_time'] = $val['creatime'];
            //         unset($val['creatime']);
            //     }
            // }
            // $ret    = $Model->db(2)->table($tableName)->addAll($list);
            if(!$ret){
                echo 'Error:'.$Model->getDbError();
                break;
            }
            $page++;
            $itemCount  += count($list);
        }

        echo 'success!'.$itemCount;
    }

}

